<?php
/*
company:tiesh.com
project:common
function: 用户

created by: Bach
created date: 2016-02-23
description:

modification v1.01
modified by: 夏浩文
description:添加getOrderListForMine方法 用户获取自己的订单

modification v1.03
modified by: Bach
description: 优化修改 2017-05-06
*/
namespace app\hongyanche\controller;
class Order
{
    //用户删除订单
    public function remove()
    {
        $order_id = input('order_id');
        $res = model('order')->cancel($order_id);
        return json($res);
    }
    //根据order_id获取信息
    public function info()
    {
        $order_id = input('order_id');
        $cafeOrder = model('cafe')->userOrderList($order_id);
        $bookOrder = model('book')->userOrderList($order_id);
        $spaceOrder = model('space')->userOrderList($order_id);
        $campaignOrder = model('campaign')->userOrderList($order_id);
        $clientOrder = model('client')->userOrderList($order_id['data']['list']);
        if($cafeOrder['state']) $cafeOrder = $cafeOrder['data']['list'];
        if($spaceOrder['state']) $spaceOrder = $spaceOrder['data']['list'];
        if($bookOrder['state']) $bookOrder = $bookOrder['data']['list'];
        if($campaignOrder['state']) $campaignOrder = $campaignOrder['data']['list'];
        if($clientOrder['state']) $clientOrder = $clientOrder['data']['list'];
        $res = array_merge($cafeOrder,$spaceOrder,$bookOrder,$campaignOrder,$clientOrder);
        if(!$res){
            $res = array('state'=>1,'data'=>array('info'=>[]));
            return json($res);
        }
        $res = array('state'=>1,'data'=>array('info'=>$res[0]));
        return json($res);
    }
    public function getlist()
    {
        $filter['page'] = input('page');
        $filter['maxPerPage'] = input('maxPerPage');
        $filter['keywords'] = input('keywords');
        $order_id = model('order')->getOrderidByUserid($filter);
        if(!$order_id['state']) return json($order_id);
        if(!$order_id['data']['list']) return json(array('data'=>array('list'=>[]),'state'=>1));
        $mall = model('mall')->userOrderList($order_id['data']['list']);
        if($mall['state']) $mall = $mall['data']['list'];
        $res = array('state' =>1,'data'=>array('list'=>$mall,'more'=>$order_id['data']['more']));
        return json($res);
    }
    
    //评论
    public function order_comment()
    {
        $order_id = input('order_id');
        $data['content'] = input('content');
        $data['comment'] = input('comment');
        $res = model('order')->comment($order_id,$data);
        return json($res);
    }
}
